﻿using System;
using System.Linq.Expressions;
using System.Runtime.Serialization;
using System.Collections.Generic;

namespace ExpressionSerialization
{
  [CollectionDataContract(ItemName = "ExpressionList")]
  public class XParameterExpressionList:List<XParameterExpression>
  {
    public XParameterExpressionList() { }

    public XParameterExpressionList(System.Collections.ObjectModel.ReadOnlyCollection<ParameterExpression> parameters_)
    {
      foreach(var item in parameters_) {
        this.Add(XExpression.CreateFromExpression(item) as XParameterExpression);
      }
    }
    //-----
  
    public List<ParameterExpression> ToParameterExpressionsList(Type dataContract_, System.Collections.Generic.List<ParameterExpression> parameters_)
    {
      List<ParameterExpression> res = new List<ParameterExpression>();
      for(int i = 0; i < Count; i++) {
        res.Add(this[i].ToExpression(dataContract_, parameters_) as ParameterExpression);
      }
      return res;
    }

  }
}
